package api

import (
	"context"
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"net/http"
	fromData "user_api/api_structure"
	"user_api/global"
	proto "user_api/proto"
	myvalidator "user_api/validator"
)

func AddUser(ctx *gin.Context) {
	rep := &proto.ResponseUserInfo{}
	AddUserData := fromData.AddUserForm{}

	if err := ctx.ShouldBind(&AddUserData); err != nil {
		myvalidator.HandleValidatorError(ctx, err)
		return
	}

	//赋值
	if err := global.SwapTo(AddUserData, rep); err != nil {
		return
	}
	zap.S().Debug("传输参数", rep)
	res, err := global.UserSrvClient.AddUser(context.TODO(), rep)

	if err != nil {
		ctx.JSON(http.StatusForbidden,
			gin.H{
				"code": http.StatusForbidden,
				"msg":  res,
			})
		return
	}
	ctx.JSON(http.StatusOK,
		gin.H{
			"code": 200,
			"msg":  "ok",
			"data": res,
		},
	)
}

func GetUserInfo(ctx *gin.Context) {
	ctx.JSON(http.StatusOK,
		gin.H{
			"code":     200,
			"total":    "ok",
			"accounts": "获取用户信息",
		})
}
